﻿@using Matrix.MaKaYunShang.BLL
@using Matrix.MaKaYunShang.Model.Enum
@model Matrix.MaKaYunShang.Model.Dto.ViewOrdersDto
@{
    ViewBag.Title = "订单详情";
    ViewBag.PathToBtn = "/Orders/List?orderStatus=" + Request["orderStatus"];
    ViewBag.TextBtn = "返回至列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section css{
    <style type="text/css">
        #assignModal {
            top: 30%;
        }

        #cancelOrRejectedModal {
            top: 30%;
        }
    </style>
}
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                订单详情（<font style="font-size: 18px;color: red">状态：@Model.OrderStatus</font>）
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-lg-12">
                        <fieldset>
                            <div class="form-group col-md-6">
                                <label>订单编号</label>
                                @Html.TextBoxFor(model => model.OrderNo, new { @class = "form-control", @readonly = "readonly" })
                            </div>
                            <div class="form-group col-md-6">
                                <label>用户微信昵称</label>
                                <input type="text" readonly="readonly" class="form-control" value="@ViewBag.NickName" />
                            </div>
                        </fieldset>
                    </div>
                </div>
                <div class="row" style="padding-left: 15px; padding-right: 15px;">
                    <div class="col-lg-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h4>收货信息</h4>
                                姓名：@Model.ReceiverName
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                电话：<a href='tel:@Model.ReceiverPhone'>@Model.ReceiverPhone</a>
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                地址：@Model.ReceiverAddress
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                备注：@Model.Remark
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row" style="padding-left: 15px; padding-right: 15px;">
                    <div class="col-lg-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h4>订单明细</h4>
                            </div>
                            <div class="panel-body">
                                <div class="table-responsive table-bordered">
                                    <table class="table">
                                        <thead>
                                            <tr>
                                                <th>商品名称</th>
                                                <th>规格</th>
                                                <th>单价</th>
                                                <th>数量</th>
                                                <th>总价</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach (var item in Model.OrderDetailList)
                                            {
                                                <tr>
                                                    <td>@Html.Raw(item.CommodityName + (item.IsGift ? "<font style='color:red'>【赠品】</font>" : ""))</td>
                                                    <td>@item.CommoditySpec</td>
                                                    <td>@item.Price</td>
                                                    <td>@item.Quantity（@item.CommodityUnit）</td>
                                                    <td>@(item.Price * item.Quantity)</td>
                                                </tr>
                                            }
                                            <tr>
                                                <td></td>
                                                <td></td>
                                                <td><b>总计</b></td>
                                                <td><b>@Model.CommodityQuantity</b></td>
                                                <td><b>￥@Model.NormalPrice</b></td>
                                            </tr>
                                            @if (Model.CouponValue > 0)
                                            {
                                                <tr>
                                                    <td></td>
                                                    <td></td>
                                                    <td><b>优惠券</b></td>
                                                    <td></td>
                                                    <td><b>-￥@Model.CouponValue</b></td>
                                                </tr>
                                            }
                                            @if (Model.RandomPayDiscount > 0)
                                            {
                                                <tr>
                                                    <td></td>
                                                    <td></td>
                                                    <td><b>立减金额</b></td>
                                                    <td></td>
                                                    <td><b>-￥@Model.RandomPayDiscount</b></td>
                                                </tr>
                                            }
                                            @if (!string.IsNullOrWhiteSpace(Model.CouponResume))
                                            {
                                                <tr>
                                                    <td></td>
                                                    <td></td>
                                                    <td><b>票券详情</b></td>
                                                    <td></td>
                                                    <td><b>@Html.Raw(Model.CouponResume)</b></td>
                                                </tr>
                                            }
                                            <tr>
                                                <td></td>
                                                <td></td>
                                                <td><b>实际支付</b></td>
                                                <td></td>
                                                <td><b style="color: red;">￥@Model.PayPrice（<b style="color: red;font-size: 18px;">@Model.PayWay</b>）</b></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row" style="padding-left: 15px; padding-right: 15px;">
                    <div class="col-lg-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                配送跟踪
                            </div>
                            <div class="panel-body">
                                <div class="table-responsive">
                                    <table class="table table-striped">
                                        @{
                                            var orderTrackingList = OrderTrackingBLL.Instance.GetOrderTrackByOrderId(Model.Id);
                                            if (orderTrackingList != null)
                                            {
                                                for (var i = 0; i < orderTrackingList.Count; i++)
                                                {
                                        <tr @(i == 0 ? "style=color:blue;" : "")>
                                            <td>@orderTrackingList[i].OptDesc</td>
                                        </tr>
                                                }
                                            }
                                        }
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                @if (!string.IsNullOrEmpty(Model.SysRemark))
                {
                    <div class="row" style="padding-left: 15px; padding-right: 15px;">
                        <div class="col-lg-12">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <h4>订单系统备注</h4>
                                    @Model.SysRemark
                                </div>
                            </div>
                        </div>
                    </div>
                }

                <div class="row">
                    <div class="col-lg-12">
                        <fieldset>
                            <div class="col-md-12">
                                @Html.Raw(ViewBag.Action)
                            </div>
                        </fieldset>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="assignModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="max-width: 300px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">订单分派</h4>
            </div>
            <div class="modal-body">
                <select class="form-control" id="Delivery">
                    @{
                        var mcList = McAccountsBLL.Instance.GetModelListWithRoleInfoByShopId(Model.ShopId, (int)CommonEnum.McAccountRole.Delivery);
                        if (mcList != null)
                        {
                            foreach (var item in mcList)
                            {
                                <option value="@item.AccountId">@item.DisplayName</option>
                            }
                        }
                    }
                </select>
            </div>
            <div class="modal-footer">
                <input type="hidden" id="hidOrderId" />
                <button type="button" class="btn btn-primary" id="btnAssign">确认分派</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="cancelOrRejectedModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="max-width: 400px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="cancelOrRejectedLabel"></h4>
            </div>
            <div class="modal-body">
                <textarea class="form-control" id="sysRemark" style="height: 80px;"></textarea>
            </div>
            <div class="modal-footer">
                <input type="hidden" id="hidSysRemarkOrderId" />
                <input type="hidden" id="hidUrl" />
                <button type="button" class="btn btn-primary" id="btnSaveSysRemark"></button>
            </div>
        </div>
    </div>
</div>
@section javascript{
    <script type="text/javascript">
    $(function () {
        $("#btnAssign").click(function () {
            $.post("@Url.Action("Assign")", "orderId=" + $("#hidOrderId").val() + "&deliveryId=" + $("#Delivery").val(), function (data) {
                if (data.Status) {
                    $("#assignModal").modal("hide");
                    alertify.success(data.Message);
                    setTimeout(function () {
                        window.location.reload();
                    }, 500);
                } else {
                    alertify.error(data.Message);
                }
            });
        });

        $("#btnSaveSysRemark").click(function () {
            var url = $("#hidUrl").val();
            var sysRemark = $("#sysRemark").val();
            if (sysRemark == "") {
                alertify.alert("请填写" + $("#cancelOrRejectedLabel").html());
                return;
            }
            $.post(url, "orderId=" + $("#hidSysRemarkOrderId").val() + "&sysRemark=" + encodeURIComponent($("#sysRemark").val()), function (data) {
                if (data.Status) {
                    $("#cancelOrRejectedModal").modal("hide");
                    alertify.success(data.Message);
                    setTimeout(function () {
                        window.location.reload();
                    }, 500);
                } else {
                    alertify.error(data.Message);
                }
            });
        });
    });

    function assign(id) {
        $("#hidOrderId").val(id);
    }

    function arrived(id) {
        alertify.okBtn("确定").cancelBtn("取消").confirm("确认已送达？", function () {
            $.post("@Url.Action("Arrived")", "orderId=" + id, function (data) {
                if (data.Status) {
                    alertify.success(data.Message);
                    setTimeout(function () {
                        window.location.reload();
                    }, 500);
                } else {
                    alertify.error(data.Message);
                }
            });
        });
    }

    function complete(id) {
        alertify.okBtn("确定").cancelBtn("取消").confirm("确认已完成？", function () {
            $.post("@Url.Action("Complete")", "orderId=" + id, function (data) {
                    if (data.Status) {
                        alertify.success(data.Message);
                        setTimeout(function () {
                            window.location.reload();
                        }, 500);
                    } else {
                        alertify.error(data.Message);
                    }
                });
            });
        }

        function cancel(id) {
            $("#sysRemark").val("");
            $("#hidUrl").val("@Url.Action("Cancel")");
            $("#hidSysRemarkOrderId").val(id);
            $("#cancelOrRejectedLabel").html("取消原因");
            $("#btnSaveSysRemark").html("确认取消");
        }

        function back(id) {
            $("#sysRemark").val("");
            $("#hidUrl").val("@Url.Action("Back")");
            $("#hidSysRemarkOrderId").val(id);
            $("#cancelOrRejectedLabel").html("退回原因");
            $("#btnSaveSysRemark").html("确认退回");
        }
    </script>
}